<form id="form_field" method="post" action="{:url('Cpattern/field')}">
{:html_usertoken()}
<input type="hidden" name="is_submit" value="1" />
<input type="hidden" name="objid" value="{$objid}" />
	<div class="form-group">
   		<div class="input-group">
   			<span class="input-group-addon" style="background:#f4f4f4;">字段名称</span>
			<input type="text" name="field[name]" class="form-control" />
   			<div class="input-group-btn c-p-field-source" title="选择数据源">
	   			<select name="field[source]" class="form-control slt-field-source">
					<optgroup label="选择数据源">
						<option value="">内容页</option>
						<option value="source_url">起始页</option>
					</optgroup>
				</select>
			</div>
   		</div>
	</div>
	<div class="form-group">
		<div class="input-group" style="margin-bottom:10px;">
			<span class="input-group-addon" style="background:#f4f4f4;">获取方式</span>
			<select name="field[module]" class="form-control">
				<option value="rule">{$Think.lang.field_module_rule}</option>
				<option value="xpath">{$Think.lang.field_module_xpath}</option>
				<option value="json">{$Think.lang.field_module_json}</option>
				<option value="auto">{$Think.lang.field_module_auto}</option>
				<option value="sign">{$Think.lang.field_module_sign}</option>
				<optgroup label="数据生成">
					<option value="words">{$Think.lang.field_module_words}</option>
					<option value="num">{$Think.lang.field_module_num}</option>
					<option value="time">{$Think.lang.field_module_time}</option>
					<option value="list">{$Think.lang.field_module_list}</option>
				</optgroup>
				<optgroup label="字段">
					<option value="extract">字段提取内容</option>
					<option value="merge">{$Think.lang.field_module_merge}</option>
				</optgroup>
			</select>
		</div>
		<div id="c_p_field_module">
			<div class="c-p-field-module" module="rule">
				{include file="cpattern:field_rule" _type="rule" _name_pre="" _allow_loop="1" /}
			</div>
			<div class="c-p-field-module" module="auto" style="display:none;">
				<div class="form-group" style="text-align:center;">
					<p>自动提取页面中的内容：</p>
				    <label class="radio-inline">
				        <input type="radio" name="field[auto]" value="title">标题
				    </label>
				    <label class="radio-inline">
				        <input type="radio" name="field[auto]" value="content">正文
				    </label>
				    <label class="radio-inline">
				        <input type="radio" name="field[auto]" value="keywords">keywords
				    </label>
				    <label class="radio-inline">
				        <input type="radio" name="field[auto]" value="description">description
				    </label>
				    <label class="radio-inline">
				        <input type="radio" name="field[auto]" value="url">页面网址
				    </label>
				    <label class="radio-inline">
				        <input type="radio" name="field[auto]" value="html">源码
				    </label>
				</div>
			</div>
			<div class="c-p-field-module" module="xpath" style="display:none;">
				{include file="cpattern:field_rule" _type="xpath" _name_pre="" _allow_loop="1" /}
			</div>
			<div class="c-p-field-module" module="words" style="display:none;">
				<textarea name="field[words]" class="form-control" rows="3">{$field['words']}</textarea>
			</div>
			<div class="c-p-field-module" module="num" style="display:none;">
				<div class="input-group">
					<div class="input-group-addon">范围</div>
					<input type="number" name="field[num_start]" class="form-control" value="{:isset($field['num_start'])?intval($field['num_start']):1}" />
					<div class="input-group-addon" style="border-left:0;border-right:0;">到</div>
					<input type="number" name="field[num_end]" class="form-control" value="{:isset($field['num_end'])?intval($field['num_end']):100}" />
		   		</div>
			</div>
			<div class="c-p-field-module" module="time" style="display:none;">
				<div class="input-group" style="margin-bottom:7px;">
					<div class="input-group-addon">格式</div>
					<input type="text" name="field[time_format]" class="form-control" />
				</div>
				<div class="help-block" id="c_p_field_time_format_list">
					<span>标签：</span>
					<ul class="in-line-mg">
						<li><a href="javascript:;" data-val="[年]">[年]</a></li>
						<li><a href="javascript:;" data-val="[月]">[月]</a></li>
						<li><a href="javascript:;" data-val="[日]">[日]</a></li>
						<li><a href="javascript:;" data-val="[时]">[时]</a></li>
						<li><a href="javascript:;" data-val="[分]">[分]</a></li>
						<li><a href="javascript:;" data-val="[秒]">[秒]</a></li>
					</ul>
				</div>
				<div class="input-group">	
					<div class="input-group-addon">范围随机</div>
					<input type="text" name="field[time_start]" class="form-control" placeholder="默认当前时间" />
					<div class="input-group-addon" style="border-left:0;border-right:0;">到</div>
					<input type="text" name="field[time_end]" class="form-control" placeholder="默认当前时间" />
		   			<div class="input-group-btn"><button type="button" class="btn btn-default" onclick="$(this).parent().siblings('input:text').val('');">清空</button></div>
		   		</div>
				<div class="checkbox"><label><input type="checkbox" name="field[time_stamp]" value="1" {$field['time_stamp']?'checked="checked"':''}> 转换成时间戳</label></div>
			</div>
			<div class="c-p-field-module" module="list" style="display:none;">
				<textarea name="field[list]" class="form-control" rows="3">{$field['list']}</textarea>
				<p class="help-block">一行一条数据，从列表中随机抽取</p>
			</div>
			<div class="c-p-field-module" module="merge" style="display:none;">
				<textarea name="field[merge]" class="form-control" rows="3">{$field['merge']}</textarea>
				<div id="c_p_field_merge_list" style="margin-top:5px;"></div>
			</div>
			<div class="c-p-field-module" module="json" style="display:none;">
				{include file="cpattern:field_rule" _type="json" _name_pre="" _allow_loop="1" /}
			</div>
			<div class="c-p-field-module" module="extract" style="display:none;">
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon" style="background:#f4f4f4;">选择字段</div>
						<select name="field[extract]" class="form-control">
							<option value="">请选择</option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<div class="input-group">
						<div class="input-group-addon" style="background:#f4f4f4;">提取内容</div>
						<select name="field[extract_module]" class="form-control">
							<option value="">请选择</option>
							<option value="cover">第一张图片</option>
							<option value="phone">电话</option>
							<option value="email">邮箱</option>
							<option value="rule">规则匹配</option>
							<option value="xpath">xpath匹配</option>
							<option value="json">json提取</option>
						</select>
					</div>
				</div>
				<div class="c-p-field-extract-module" extract-module="rule" style="display:none;">
					{include file="cpattern:field_rule" _type="rule" _name_pre="extract_" _allow_loop="" /}
				</div>
				<div class="c-p-field-extract-module" extract-module="xpath" style="display:none;">
					{include file="cpattern:field_rule" _type="xpath" _name_pre="extract_" _allow_loop="" /}
				</div>
				<div class="c-p-field-extract-module" extract-module="json" style="display:none;">
					{include file="cpattern:field_rule" _type="json" _name_pre="extract_" _allow_loop="" /}
				</div>
			</div>
			<div class="c-p-field-module" module="sign" style="display:none;">
				<div class="form-group">
					<textarea name="field[sign]" class="form-control" rows="3" placeholder="填入数据源页面中区域规则或网址规则里的{:cp_sign('match')}标签">{$field['sign']}</textarea>
					<div id="c_p_field_sign_list" style="margin-top:10px;"></div>
					<p class="help-block">如果区域和网址中存在同名标签,实际获取网址中的标签</p>
				</div>
			</div>
		</div>
	</div>
	<div class="form-group form-group-sm">
 		<button type="submit" class="btn btn-primary btn-block">确定</button>
 	</div>
</form>

<script type="text/javascript">
{if condition="$field"}
c_pattern.cpField.init({$field|json_encode});
{else /}
c_pattern.cpField.init();
{/if}
</script>